﻿using AutoMapper;
using B.S.Data.MES.API.Applications.BaseData.Command.CheJianCommand;
using B.S.Domain.BasicData.Factory_modeling.shop_management;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ChejianCommandHandlers
{
    public class AddShuXingCommandHandlers : IRequestHandler<AddShuXingCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<shuXing> attribute;
        private readonly IMapper mapper;

        public AddShuXingCommandHandlers(IBaseRepository<shuXing> attribute,IMapper mapper)
        {
            this.attribute = attribute;
            this.mapper = mapper;
        }
        public async Task<APIRequst<int>> Handle(AddShuXingCommand request, CancellationToken cancellationToken)
        {

            shuXing shop = mapper.Map<shuXing>(request);
            Random random = new Random();
            shop.DataType=random.Next(0,5);
            await attribute.Add(shop);
             return new APIRequst<int> 
             {
                    Code=RequstCode.成功,
                    Msg=RequstCode.成功.ToString(),
             };
        }
    }
}
